package com.atguigu.gulimall.cart.vo;

import java.math.BigDecimal;
import java.util.List;

public class Cart {
    private List<CartItem> cartItems;
    private Integer countNum;
    private Integer countType;
    private BigDecimal totalAmount;
    private BigDecimal reduce=new BigDecimal("0");

    public List<CartItem> getCartItems() {
        return cartItems;
    }

    public void setCartItems(List<CartItem> cartItems) {
        this.cartItems = cartItems;
    }

    public Integer getCountNum() {
        Integer count =0;
        if (this.cartItems!=null && this.cartItems.size()>0){

            for (CartItem cartItem : this.cartItems) {
                count+=cartItem.getCount();
            }
        }

        return count;
    }



    public Integer getCountType() {
        Integer count =0;
        if (this.cartItems!=null && this.cartItems.size()>0){

            for (CartItem cartItem : this.cartItems) {
                count+=1;
            }
        }

        return count;
    }



    public BigDecimal getTotalAmount() {
        BigDecimal totalAmount = new BigDecimal("0");
        if (this.cartItems!=null && this.cartItems.size()>0){
            for (CartItem cartItem : this.cartItems) {
                if (cartItem.getCheck()){

                    totalAmount=totalAmount.add(cartItem.getTotalPrice());
                }
            }
        }
        totalAmount=totalAmount.subtract(getReduce());
        return totalAmount;
    }



    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
